﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenHardwareMonitor.Hardware;

namespace RemoteHardwareMonitor
{
    /// <summary>
    /// This class creates dictionaries linking temperature and load sensors by name to their index in each IHardware devices ISensor array.
    /// </summary>
    class SensorMap
    {

       private List<Dictionary<string, int>> _CPUMap = new List<Dictionary<string, int>>();

       private List<Dictionary<string, int>> _GPUMap = new List<Dictionary<string, int>>();


       public List<Dictionary<string, int>> CPUMap
       {
           get { return _CPUMap; }
       }

       public List<Dictionary<string, int>> GPUMap
       {
           get { return _GPUMap; }
       } 

        public SensorMap(IHardware[] GPUs, IHardware[] CPUs)
        {
            CreateMaps(GPUs, CPUs);

        }


        private void CreateMaps(IHardware[] GPUs, IHardware[] CPUs)
        {
            _CPUMap = CreateMap(CPUs);
            _GPUMap = CreateMap(GPUs);

        }

        private List<Dictionary<string, int>> CreateMap(IHardware[] hardware)
        {
            List<Dictionary<string, int>> hardwareMap = new List<Dictionary<string, int>>();
            Dictionary<string, int> sensorMap = new Dictionary<string, int>();
            foreach (IHardware h in hardware)
            {
                sensorMap.Clear();
                int sensorIndex = 0;
                foreach (ISensor s in h.Sensors)
                {

                    switch (s.SensorType)
                    {
                        case SensorType.Temperature:
                            sensorMap.Add(s.Name + " Temperature", sensorIndex);
                            break;

                        case SensorType.Load:
                            sensorMap.Add(s.Name + " Load", sensorIndex);

                            break;

                    }
                    sensorIndex++;
                }

                hardwareMap.Add(sensorMap);
            }

            return hardwareMap;
        }



    }
}
